// pages/contributor/means/means.js
var util = require("../../../utils/util.js"),
  api = require("../../../utils/api.js"),
  app = getApp(); 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bangsHeight: wx.getStorageSync('navBarObj').bangsHeight,
    headimgurl: "",
    baseImgUrl: app.globalData.baseImgUrl,
    alias_nickname:''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onShow(options) {
    this.getMemberInfo()
  },
  showImage: function (event) {
    const {
      src,
      list
    } = event.currentTarget.dataset;
    wx.previewImage({
      current: src,
      urls: Array.isArray(list) ? list.map(o => this.data.baseImgUrl + o) : [src]
    })
  },
  getMemberInfo() {
    api.default.getUserInfo().then(res => {
      let {data}=res;
      this.setData({
        headimgurl: data.headimgurl ? res.data.headimgurl : '',
        alias_nickname: data.alias_nickname
      })
    })
  },
  userFrom(e) {
    this.setData({
      alias_nickname: e.detail
    })
  },
  gotoNext(e) {
    let {
      alias_nickname,
      headimgurl
    } = this.data;
    if (!headimgurl)return wx.showToast({title: '头像未上传',icon: 'none'});
    if (!alias_nickname)return wx.showToast({title: '昵称未填写',icon: 'none'});
    api.default.setMemberInfo({alias_nickname,headimgurl}).then(res => {
      wx.hideLoading() 
      if (res.code == 1) { 
        wx.showToast({
          title: '操作成功！',
          icon: 'success'
        });
        this.getMemberInfo();
      } else { 
        return wx.showToast({
          title: res.msg, 
          icon: 'none'
        })
      }
    })
  }
})